package util;

public class Color {
    
	public final static int WHITE = getColorRGBAi(255, 255, 255, 255);
	public final static int BLACK = getColorRGBAi(0, 0, 0, 255);
	public final static int RED = getColorRGBAi(255, 0, 0, 255);
	public final static int GREEN = getColorRGBAi(0, 255, 0, 255);
	public final static int BLUE = getColorRGBAi(0, 0, 255, 255);
	public final static int YELLOW = getColorRGBAi(255, 255, 0, 255);
	public final static int CYAN = getColorRGBAi(0, 255, 255, 255);
	public final static int MAGENTA = getColorRGBAi(255, 0, 255, 255);
	
    private Color() {
        
    }

    public static boolean isTransparent(int color) {
        int a = color >> 24 & 0xFF;
		int r = color >> 16 & 0xFF;
		int g = color >> 8 & 0xFF;
		int b = color & 0xFF;
        return (a == 0 || (r == 255 && g == 0 && b == 255));
    }
    
    public static int getAlphaCopy(int color, int alpha) {
		int r = color >> 16 & 0xFF;
		int g = color >> 8 & 0xFF;
		int b = color & 0xFF;
        return getColorRGBAi(r, g, b, alpha);
    }
    
    public static int[] getComponentARGBi(int argb) {
        int a = argb >> 24 & 0xFF;
		int r = argb >> 16 & 0xFF;
		int g = argb >> 8 & 0xFF;
		int b = argb & 0xFF;
        return new int[] {a, r, g, b};
    }
    
    public static float[] getComponentARGBf(int argb) {
        int a = argb >> 24 & 0xFF;
		int r = argb >> 16 & 0xFF;
		int g = argb >> 8 & 0xFF;
		int b = argb & 0xFF;
        return new float[] {a / 255f, r / 255f, g / 255f, b / 255f};
    }
    
    public static int getColorRGBAi(int r, int g, int b, int a) {
        return (a << 24 | r << 16 | g << 8 | b);
    }
    
    public static int getColorRGBAf(float r, float g, float b, float a) {
        return getColorRGBAi((int)(255f * r), (int)(255f * g), (int)(255f * b), (int)(255f * a));
    }
    
    public static int getColorARGBi(int a, int r, int g, int b) {
        return (a << 24 | r << 16 | g << 8 | b);
    }
    
    public static int getColorARGBf(float a, float r, float g, float b) {
        return getColorARGBi((int)(255f * a), (int)(255f * r), (int)(255f * g), (int)(255f * b));
    }
    
    public static int getColorRGBi(int r, int g, int b) {
        return (255 << 24 | r << 16 | g << 8 | b);
    }
    
    public static int getColorRGBf(float r, float g, float b) {
        return getColorRGBi((int)(255f * r), (int)(255f * g), (int)(255f * b));
    }
    
    public static int getColorARGBComponent(int[] argb) {
        return getColorARGBi(argb[0], argb[1], argb[2], argb[3]);
    }
    
    public static int getColorRGBAComponent(int[] rgba) {
        return getColorRGBAi(rgba[0], rgba[1], rgba[2], rgba[3]);
    }
    
    public static int limitPlanei(int plane) {
        if (plane <= 0) {
            return 0;
        } else if (plane >= 255) {
            return 255;
        } else {
            return plane;
        }
    }
    
    public static float limitPlanef(float plane) {
        if (plane <= 0f) {
            return 0f;
        } else if (plane >= 1f) {
            return 1f;
        } else {
            return plane;
        }
    }
    
}
